package demo2;

import java.util.Comparator;

public class NameComparator implements Comparator<Person> {
    @Override
    public int compare(Person o1, Person o2) {//因为名字是引用类型，不能直接比较大小，故需要调用compareTo来比较
        return o1.name.compareTo(o2.name);
    }
}
